package org.tlipoca.smarticletagrelational.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.genntii.smcommon.result.Result;
import org.genntii.smdomain.dto.ArticleTagRelationalDTO;
import org.genntii.smdomain.entity.ArticleTagRelational;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tlipoca.smarticletagrelational.service.ArticleTagRelationalService;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Map;

@Tag(name = "文章标签关系")
@Slf4j
@RestController
@RequestMapping("/article_tag_relational")
public class ArticleTagRelationalController {

    @Autowired
    private ArticleTagRelationalService articleTagRelationalService;

    @Operation(summary = "根据文章ID获取文章标签ID列表")
    @GetMapping("/{articleId}")
    public Result<ArrayList<ArticleTagRelational>> getArticleTagRelationalByArticleId(@PathVariable Long articleId) {
        return Result.success(articleTagRelationalService.getArticleTagRelationalByArticleIdService(articleId));
    }

    @Operation(summary = "批量根据文章ID获取文章标签ID列表")
    @GetMapping
    public Result<Map<String , ArrayList<Long>>> getTagIdsByArticleIds(@RequestParam("articleIds")ArrayList<Long> articleIds) {
        return Result.success(articleTagRelationalService.getTagIdsByArticleIds(articleIds));
    }

    @Operation(summary = "文章批量新增标签")
    @PostMapping
    public Result addArticleTagRelational(@RequestBody ArticleTagRelationalDTO articleTagRelationalDTO) {
        articleTagRelationalService.addArticleTagRelationalService(articleTagRelationalDTO);
        return Result.success();
    }

    @Operation(summary = "更新文章标签")
    @PutMapping
    public Result updateArticleTagRelational(@RequestBody ArticleTagRelationalDTO articleTagRelationalDTO) {
        articleTagRelationalService.updateArticleTagRelationalService(articleTagRelationalDTO);
        return Result.success();
    }

    @Operation(summary = "删除文章标签")
    @DeleteMapping
    public Result deleteArticleTagRelational(@RequestBody ArticleTagRelationalDTO articleTagRelationalDTO) {
        articleTagRelationalService.deleteArticleTagRelationalService(articleTagRelationalDTO);
        return Result.success();
    }

    @Operation(summary = "删除文章全部标签")
    @DeleteMapping("/{articleId}")
    public Result deleteArticleTagRelationalBatch(@PathVariable Long articleId) {
        articleTagRelationalService.deleteArticleTagRelationalBatch(articleId);
        return Result.success();
    }

}
